package com.wufeng.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.wufeng.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@DefaultProperties(defaultFallback = "paymentHandler")
public class OrderController {
    @Resource
    private PaymentService paymentService;

    @RequestMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfoOK(@PathVariable Integer id) {
        log.info("输入参数: {}", id);
        return paymentService.paymentInfo_OK(id);
    }

//    @HystrixCommand(fallbackMethod = "paymentInfoTimeOutHandler", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
//    })
//    @HystrixCommand
    @RequestMapping("/consumer/payment/hystrix/timeout/{id}")
    public String paymentInfoTimeOut(@PathVariable Integer id) {
        log.info("输入参数: {}", id);
        return paymentService.paymentInfo_TimeOut(id);
    }

    public String paymentInfoTimeOutHandler(@PathVariable Integer id) {
        log.info("输入参数: {}", id);
        return "服务超时或者服务报错,当前线程：" + Thread.currentThread().getName();
    }

    public String paymentHandler() {
//        log.info("输入参数: {}", id);
        return "公共fallbackMethod,当前线程：" + Thread.currentThread().getName();
    }
}

